package com.ht.config.quartz;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;
import org.springframework.stereotype.Component;

/**
 * 定时任务监听器
 */
@Component
public class JobLogListener implements JobListener {

    @Override
    public String getName() {
        return "JobLogListener";
    }

    @Override
    public void jobToBeExecuted(JobExecutionContext context) {
        System.out.println("任务将要执行：" + context.getJobDetail().getKey());
    }

    @Override
    public void jobExecutionVetoed(JobExecutionContext context) {
        System.out.println("任务被否决执行：" + context.getJobDetail().getKey());
    }

    @Override
    public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
        if (jobException == null) {
            System.out.println("任务成功执行：" + context.getJobDetail().getKey());
        } else {
            System.out.println("任务执行异常：" + context.getJobDetail().getKey() + ", 异常：" + jobException.getMessage());
        }
    }
}
